import os.path

# 想直接读取二进制数据到一个可变缓冲区中，而不需要做任何的中间复制操作
def demo_1():
    filename = '../temp/sample.bin'

    with open(filename, 'wb') as f:
        f.write(b'Hello kepler aaaaa')
    buf = bytearray(os.path.getsize(filename))

    with open(filename, 'rb') as f:
        # readinto()方法能被用来为预先分配内存的数据填充数据
        f.readinto(buf)
    print(buf)

if __name__ == '__main__':
    demo_1()